package cn.bluejoe.elfinder.flter;

import cn.bluejoe.elfinder.servlet.LoginServlet;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class UserFilter implements Filter {

    public static String password = "123123ww";

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        password = filterConfig.getInitParameter("password");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request1 = (HttpServletRequest)request;
        HttpSession session = request1.getSession();
        Object f = session.getAttribute(LoginServlet.LOGIN);
        if(null != f && (Boolean) f){
            chain.doFilter(request, response);
        }else{
            ((HttpServletResponse)response).sendRedirect(request.getServletContext().getContextPath()+"/login.html");
            return;
        }
    }

    @Override
    public void destroy() {

    }
}
